package com.xzz;

/**
 * @author: hhz
 * @create: 2021-12-06 15:16
 **/
public class MoveZeroes {

    public static void main(String[] args) {
        int[] nums = new int[]{0, 1, 32, 0, 2, 3, 0, 12, 34};
//        int[] nums = new int[]{12, 3, 0, 1, 0};
        moveZeroes(nums);
        System.out.println();
        moveZeroes2(nums);
        System.out.println();
        Integer integer1 = 23;
        Integer integer2 = 23;

        Integer integer3 = Integer.valueOf(222);
        Integer integer4 = 222;
        System.out.println(integer1.equals(integer2));
        System.out.println(integer3.equals(integer4));
        System.out.println(integer1==integer2);
        System.out.println(integer3==integer4);

        String s1 = new String("iByteCode");
        String s2 = "bbbb" + "ccccc";
        String s3 = "dddd" + s2;
        System.out.println(s3);
    }

    public static void moveZeroes(int[] nums) {
        int temp;//定义一个临时变量
        for (int i = 0; i < nums.length - 1; i++) {//冒泡趟数
            for (int j = 0; j < nums.length - i - 1; j++) {
                if (nums[j] == 0) {
                    temp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = temp;
                }
            }
        }
        for (int num : nums) {
            System.out.print(num + " ");
        }

    }

    public static void moveZeroes2(int[] nums) {
        int len = nums.length, right = 0, left = 0;
        while (right < len) {
            if(nums[right]!=0){
                int temp = nums[left];
                nums[left] = nums[right];
                nums[right] = temp;
                left++;
            }
            right++;
        }
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }
}
